package TestDemo.service;

import TestDemo.datbase.DataBaseDemo;
import utils.C3P0Util;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author xxx
 * @date 2021/1/11 17:29
 * @description
 */
public class ServiceDemo {
    public void  serviceDemo(String a,String b,double money){
        Connection connection=null;
        try {
         connection= C3P0Util.getConnection();
         connection.setAutoCommit(false);

         DataBaseDemo dataBaseDemo=new DataBaseDemo();
         dataBaseDemo.dateTom(connection,a,money);

            System.out.println(1/0);
          dataBaseDemo.dateJerry(connection,b,money);



          connection.commit();
        } catch (SQLException e) {
            e.printStackTrace();
            if(connection!=null){
                try {
                    connection.rollback();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
        }
        C3P0Util.release(connection,null,null);
    }
}
